package kayao.client;

import kayao.client.data.SharedMemory;
import kayao.client.network.login.LoginThread;
import kayao.common.KayaoValues;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends Activity implements LoginListener, OnClickListener {
	private EditText mNameField;
	private EditText mAddressField;
	private Button mLoginButton;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);

		mNameField = (EditText)findViewById(R.id.EditText01);
		mAddressField = (EditText)findViewById(R.id.EditText02);
		mAddressField.setText(KayaoValues.SERVER_IP);
		mLoginButton = (Button)findViewById(R.id.Button01);
		mLoginButton.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		KayaoValues.SERVER_IP = mAddressField.getText().toString();
		LoginThread loginThread = new LoginThread(mNameField.getText().toString());
		loginThread.setLoginListener(this);
		loginThread.start();
	}

	@Override
	public void onLogin() {
		SharedMemory.getInstance().setName(mNameField.getText().toString());
		startActivity(new Intent(this, KayaoActivity.class));
	}

	@Override
	public void onLoginFailed(String msg) {
	}
}
